package com.ruoyi.course.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CourseImages;
import com.ruoyi.course.service.ICourseImagesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程图片管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/course/images")
public class CourseImagesController extends BaseController
{
    @Autowired
    private ICourseImagesService courseImagesService;

    /**
     * 查询课程图片管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:images:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseImages courseImages)
    {
        startPage();
        List<CourseImages> list = courseImagesService.selectCourseImagesList(courseImages);
        return getDataTable(list);
    }

    /**
     * 导出课程图片管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:images:export')")
    @Log(title = "课程图片管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseImages courseImages)
    {
        List<CourseImages> list = courseImagesService.selectCourseImagesList(courseImages);
        ExcelUtil<CourseImages> util = new ExcelUtil<CourseImages>(CourseImages.class);
        util.exportExcel(response, list, "课程图片管理数据");
    }

    /**
     * 获取课程图片管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:images:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(courseImagesService.selectCourseImagesById(id));
    }

    /**
     * 新增课程图片管理
     */
    @PreAuthorize("@ss.hasPermi('course:images:add')")
    @Log(title = "课程图片管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseImages courseImages)
    {
        return toAjax(courseImagesService.insertCourseImages(courseImages));
    }

    /**
     * 修改课程图片管理
     */
    @PreAuthorize("@ss.hasPermi('course:images:edit')")
    @Log(title = "课程图片管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseImages courseImages)
    {
        return toAjax(courseImagesService.updateCourseImages(courseImages));
    }

    /**
     * 删除课程图片管理
     */
    @PreAuthorize("@ss.hasPermi('course:images:remove')")
    @Log(title = "课程图片管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(courseImagesService.deleteCourseImagesByIds(ids));
    }
}
